package dao

import (
	"hft/Http/Models/request"

	"gorm.io/gorm"
)

type LouPanSwiper struct{}

func (l *LouPanSwiper) JustCategory(category int, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if category == 0 {
			return db
		} else {
			return db.Where("category = ?", category)
		}
	}
}

func (l *LouPanSwiper) JustLouPan(louPanId int, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if louPanId == 0 {
			return db
		} else {
			return db.Where("lou_pan_id = ?", louPanId)
		}
	}
}

func (l *LouPanSwiper) GetSwiperList(paginate *request.LouPanSwiperSearch, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		return db.Scopes(l.JustCategory(paginate.Category, db)).Scopes(l.JustLouPan(paginate.LouPanId, db)).Scopes(Paginate(Page(paginate.Page), db)).Order("sort desc")
	}
}

var LouPanSwiperDao = new(LouPanSwiper)
